﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Catering_DBOpertion;
using System.Data.SqlClient;
using System.Data;

namespace Catering_Operation
{
    class DailyContraPerson
    {
        public DailyContraPerson()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
            return DbHelperSQL.GetMaxID("id", "DailyContraPerson"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int id)
		{
			StringBuilder strSql=new StringBuilder();
            strSql.Append("select count(1) from DailyContraPerson");
			strSql.Append(" where id=@id ");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)};
			parameters[0].Value = id;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
        public void Add(Catering_Model.DailyContraPerson oMD)
		{
			StringBuilder strSql=new StringBuilder();
            strSql.Append("insert into DailyContraPerson(");
            strSql.Append("DailyContraID,ContractorInfoID)");
			strSql.Append(" values (");
            strSql.Append("@DailyContraID,@ContractorInfoID)");
            SqlParameter[] prams = {
					new SqlParameter("@DailyContraID", SqlDbType.Int, 4),
					new SqlParameter("@ContractorInfoID", SqlDbType.Int, 4)};
            prams[0].Value = oMD.DailyContraID;
            prams[1].Value = oMD.ContractorInfoID;
            DbHelperSQL.ExecuteSql(strSql.ToString(), prams);
		}
		
		/// <summary>
		/// 删除一条数据
		/// </summary>
        public bool Delete(int DailyContraID, int ContractorInfoID)
		{
			
			StringBuilder strSql=new StringBuilder();
            strSql.Append("delete from DailyContraPerson ");
            strSql.Append(" where DailyContraID=@DailyContraID AND ContractorInfoID=@ContractorInfoID ");
            SqlParameter[] prams = {
					new SqlParameter("@DailyContraID", SqlDbType.Int, 4),
					new SqlParameter("@ContractorInfoID", SqlDbType.Int, 4)};
            prams[0].Value = DailyContraID;
            prams[1].Value = ContractorInfoID;
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), prams);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			StringBuilder strSql=new StringBuilder();
            strSql.Append("delete from DailyContraPerson ");
            strSql.Append(" where " + idlist);
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
        
		#endregion  Method
    }
}
